package com.example.day07_zhongji.fragment;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.text.GetChars;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.day07_zhongji.R;
import com.example.day07_zhongji.adapter.WorkAdapter;
import com.example.day07_zhongji.base.BaseFragment;
import com.example.day07_zhongji.bean.WorkBean;
import com.example.day07_zhongji.presenter.WorkPresenter;
import com.example.day07_zhongji.view.WorkView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class WodeFragment extends BaseFragment<WorkPresenter> implements WorkView {
    @BindView(R.id.recyler)
    RecyclerView mrecycler;
    private ArrayList<WorkBean.ResultsBean> resultsBeans;
    private WorkAdapter workAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mrecycler.setLayoutManager(new LinearLayoutManager(getContext()));
        mrecycler.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        resultsBeans = new ArrayList<>();
        workAdapter = new WorkAdapter(getContext(), resultsBeans);
        mrecycler.setAdapter(workAdapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter=new WorkPresenter();
        mPresenter.getdata();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_wode;
    }

    @Override
    public void onSuccess(WorkBean data) {
        List<WorkBean.ResultsBean> results = data.getResults();
        resultsBeans.addAll(results);
        workAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {
        Toast.makeText(getContext(),error,Toast.LENGTH_LONG).show();

    }

    @Override
    public void showToast(String str) {
        Toast.makeText(getContext(),str,Toast.LENGTH_LONG).show();

    }
}
